public class Leetcode3127 {
    public static void main(String[] args) {
        char[][] grid = {{'B', 'W', 'B' }, {'B', 'W', 'W' }, {'B', 'W', 'B' }};
        boolean res = canMakeSquare(grid);
        System.out.println(res);
    }

    public static boolean canMakeSquare(char[][] grid) {
        for (int i = 0; i < grid.length - 1; i++) {
            for (int j = 0; j < grid[0].length - 1; j++) {
                int countW = 0;
                int countB = 0;
                if (grid[i][j] == 'B') {
                    countB++;
                } else {
                    countW++;
                }

                if (grid[i + 1][j] == 'B') {
                    countB++;
                } else {
                    countW++;
                }

                if (grid[i][j + 1] == 'B') {
                    countB++;
                } else {
                    countW++;
                }

                if (grid[i + 1][j + 1] == 'B') {
                    countB++;
                } else {
                    countW++;
                }
                if (countB >= 3 || countW >= 3) {
                    return true;
                }
            }
        }
        return false;
    }
}
